/**author:yebinx email:yebinx@21cm.com*/
export default class LineImgEff extends Laya.Sprite{
	public static FLAG:string="LineImgEff";
	private body:Laya.Image;
	private mSkin:string;
	/*0水平，1垂直**/
	private mBodyDir:number;
	private mWidth:number;
	constructor(_skin:string,_width:number=50,_dir:number=0){
		super();
		this.mSkin=_skin;
		this.mBodyDir=_dir;
		this.mWidth=_width;
		this.body=new Laya.Image(this.mSkin);
		this.addChild(this.body);
	}
	
	public setData(_value:number,_x:number,_y:number,_dir:number=0,func:Function=null){
		this.setPos(_x,_y);
		this.updateRot(_dir);
		this.lenTw(_value,func);
	}
	
	public lenTw(_value:number,func:Function=null){
		let tparams:any={width:_value}
		if(this.mBodyDir==0){
			this.body.width=0;
		}else{
			this.body.height=0;
			 tparams={height:_value}
		}
		Laya.Tween.to(this.body,tparams,200,null,new Laya.Handler(this,()=>{
			if(func)func();
			this.remvoe();
		}));
	}
	
	public setPos(_x:number,_y:number){
		let toff = this.getOffPos();
		this.pos(_x+toff.x,_y+toff.y);
	}
	
	public updateRot(_dir:number=0){
		this.body.rotation = this.getRot(_dir);
	}
	/*0上1下2左3右**/
	private getRot(_dir:number=0){
		let trot=0;
		switch(_dir){
			case 0:
				trot= this.mBodyDir==0?-90:180;
			break;
			case 1:
				trot= this.mBodyDir==0?90:0;
			break;
			case 2:
				trot= this.mBodyDir==0?180:90;
			break;
			case 3:
				trot= this.mBodyDir==0?0:-90;
			break;
		}
		return trot;
	}
	
	private getOffPos(_dir:number=0){
		let tx:number=0;
		let ty:number=0;
		switch(_dir){
			case 0:
				tx= this.mBodyDir==0?0:this.mWidth;
				ty= this.mBodyDir==0?this.mWidth:0;
			break;
			case 1:
				tx= this.mBodyDir==0?-this.mWidth:0;
				//ty= this.mBodyDir==0?0:0;
			break;
			case 2:
				tx= this.mBodyDir==0?0:this.mWidth;
				ty= this.mBodyDir==0?this.mWidth:0;
			break;
			case 3:
				//tx= this.mBodyDir==0?0:this.mWidth;
				ty= this.mBodyDir==0?0:this.mWidth;
			break;
		}
		return {x:tx,y:ty};
	}
	
	public remvoe(){
		this.removeSelf();
		Laya.Pool.recover(LineImgEff.FLAG, this);
	}
	


}